# cxxomfort-examples
Examples for using the cxxomfort backports library

----

This is a set of usage examples for `cxxomfort`, the backports library for C++, 
intended both as a demonstration of the working features and as a 
provision of code samples when pointing users to the library.

Instructions
------------

Have the cxxomfort library (version with `CXXOMFORT_DATE >= 20210101`) installed. 
Pick the example you want and compile.

In order to work correctly, you can do any of the following:

* Copy or link the `cxxomfort/` directory of the distribution into your compiler's system search path (`/usr/local/include/`  or similar).
* Add the path with `-I /path/to/cxxomfort`, or the equivalent option for your compiler / project.



Current Examples
----------------

The listing of examples includes but is not limited to:

1.- Showing information about cxxomfort and support.

* `0info.cpp` - shows basic information, in particular detected compiler setup.
* `0showsupport.cpp` - besides the above, shows specific information about features detected and supported by the library.

2.- Basic demonstrations - flexing one feature at a time.

* `algorithms.cpp` - simple showcase of some of the features in `<algorithm>`.
* `any.cpp` - C++17's `std::any` backport (needs the _vocabulary_ extension).
* `byte17.cpp` - C++17's `std::byte` backport, showcasing the usage of the byte type, and initialization before C++17's rules.
* `decay.cpp` - C++11's `std::decay` type transformation.
* `endian.cpp` - C++20's `std::endian` backport, showing architecture-specific information.
* `gcd.cpp` - `std::gcd` and the pre-C++14 static version `static_gcd` part of cxxomfort:library.
* `generic_errors.cpp` - showcases the C++11 `<system_error>` features.
* `make_array.cpp` - shows experimental's make_array, which didn't make it to Standard before `to_array()` was introduced but is still useful for pre-C++17 code.
* `optional.cpp` - C++17's `std::optional` backport (needs the _vocabulary_ extension).
* `randonly.cpp` - example use of utilities related to `<random>` as well as iterator accessors.
* `plus.cpp` - backports of C++14's "heterogeneous functors" (`plus<void>` and the like), as well as foreach emulation.
* `string_helpers` - showcases the use of cxxomfort's nonmember string helpers, for compatibility of strings-related code before and after C++20's extensions.
* `string_view.cpp` - backports of C++17's `string_view` utility, as well as showing related helpers.
* `to_string.cpp` - C++11's `to_string` backport.
* `tuple_get.cpp` - `tuple<type>` access elements by type, as well as testing features such as `static_assert`.

3.- Showcasing libraries and supplementals.

* `explicit_cast.cpp` - `explicit_cast` and explicit conversion operator emulation.
* `foreach.cpp` - foreach loop emulation feature (equivalent to `for (v : sequence) { ... }`), part of cxxomfort:library; among other things.
* `to_string-variadic.cpp` - extended variadic `to_string` proposal (p0117r0) in cxxomfort:library.
* `tuple_pop.cpp` - showcases cxxomfort's push, pop and shift operations for tuples.
* `type_name.cpp` cxxomfort:library's `typeid_demangle()` and `type_name<>` utilities.
* `typesafe_enum.cpp` showcases the typesafe enum implementation, an alternative to C++11's `enum class`.

4.- Examples adapted from external sources.

The examples in `examples/cppref` and `examples/cplusplus` have been adapted from the cppreference and cplusplus sites for use with cxxomfort. For exmple but not limited to:

* `invoke.cpp` - the `std::invoke` example showcasing invocation of functions and function objects.
* `midpoint.cpp` - the `std::midpoint` example for the new C++20 utility.
* `typeindex.cpp` - `std::type_index` and its use in hashes.
* `unique_ptr.cpp` - the `unique_ptr<>` example lifted from cppreference / cplusplus.



Notes
-----

**Testing Environments**

Unless specified otherwise in any of the source files, 
these examples have been tested in most or all of the 
following environments:

* GCC 4.8 in C++03 mode.
* GCC 4.8 with `--std=c++0x` / `--std=c++11`.
* GCC 6.0 in C++11 mode.
* MSVC 2012 Express.
* Clang 4.0 in C++11 mode.
* Clang 6.0 in C++11 and C++14 mode.

All compiler configurations and limitations apply as per cxxomfort manual's Per-Compiler Notes.

For more information read cxxomfort configuration.

